package com.youngball.business.dao.redis.task;

import com.dyuproject.protostuff.runtime.RuntimeSchema;
import com.youngball.business.dao.redis.BaseRedisDao;
import com.youngball.business.entity.AutoLightTask;
import org.springframework.stereotype.Repository;

/**
 * redis封装
 * Created by liaopingzhu on 2017/1/13.
 */
@Repository(value = "newTaskRedisDao")
public class NewTaskRedisDao extends BaseRedisDao<Object,Object> {

    private RuntimeSchema<AutoLightTask> schema = RuntimeSchema.createFrom(AutoLightTask.class);

    /**
     * 设置定时任务到redis中
     * @param autoLightTask
     * @return
     */
    public void setCloseLightJob(AutoLightTask autoLightTask){
        try {
            String key = "handlight:" + autoLightTask.getUuid();
            this.getRedisTemplate().opsForValue().set(key,autoLightTask);
            this.getRedisTemplate().expireAt(key,autoLightTask.getTimeDate());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 删除redis中的元素记录
     * @param key
     */
    public void deleteByKey(String key){
        try {
            this.getRedisTemplate().delete("handlight:" + key);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
